package java101;
//Import Java programs
import java.text.NumberFormat;
import java.util.Scanner;

import javax.swing.JOptionPane;

public class TempConverterFirstThreeParts {

	static Scanner sc = new Scanner(System.in);		
	public static void main(String[] args)				
	{
		//Declare the variables
		double finalTemp;
		String degString;
		
		//Display and get the text and input data
		degString = JOptionPane.showInputDialog
			("Enter the temperature, prefixed by 'c' or 'f': ");
		
		//Do the math
		//MATH DOES NOT WORK PROPERLY
		if (degString.startsWith("c")) {
			String degNoLetter = degString.substring(1);
			double degDouble = Double.parseDouble(degNoLetter);
			
			finalTemp = (degDouble-32) * (5 / 9);
			
			NumberFormat cf = NumberFormat.getNumberInstance();
			cf.setMinimumFractionDigits(0);
			cf.setMaximumFractionDigits(2);

			String unitFinal = "F";
			
			//Display the result
			System.out.println("The temperature is:  " + finalTemp + " deg " + unitFinal + ".");		
			
		}
		else if (degString.startsWith("f")) {
			String degNoLetter = degString.substring(1);
			double degDouble = Double.parseDouble(degNoLetter);
			
			finalTemp = 9 * degDouble / 5 + 32;
			
			NumberFormat cf = NumberFormat.getNumberInstance();
			cf.setMinimumFractionDigits(0);
			cf.setMaximumFractionDigits(2);
			
			String unitFinal = "C";
			
			//Display the result
			System.out.println("The temperature is:  " + finalTemp + " deg " + unitFinal + ".");	
			
		}
		else {

		}
	}

}

//Run the program and enter an number into the console. Hit enter and it returns the temperature in Fahrenheit back to you.
